/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件类型（零件、外置、索引文件、紧固件）
 *
 * @author hxloongs
 * @date 2024-8-13
 */
@AllArgsConstructor
@Getter
public enum PartFileTypeEnum {
    PART("part", "零件"),
    EXTERNAL("external", "外置"),
    INDEX("index", "索引文件"),
    FASTENER("fastener", "紧固件");

    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        PartFileTypeEnum compressionTypeEnum = forValue(value);
        if (compressionTypeEnum == null) {
            return null;
        }
        return compressionTypeEnum.getDesc();
    }

    public static PartFileTypeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (PartFileTypeEnum compressionTypeEnum : PartFileTypeEnum.values()) {
            if (compressionTypeEnum.getValue().equals(value)) {
                return compressionTypeEnum;
            }
        }
        return null;
    }

    public static PartFileTypeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (PartFileTypeEnum compressionTypeEnum : PartFileTypeEnum.values()) {
            if (desc.equals(compressionTypeEnum.getDesc())) {
                return compressionTypeEnum;
            }
        }
        return null;
    }


    /**
     * 判断是不是 零件或者紧固件
     */
    public static Boolean checkPartAndFastener(String fileType) {
        if (StringUtils.isBlank(fileType)) {
            return Boolean.FALSE;
        }
        List<String> partAndFastenerList = new ArrayList<>();
        partAndFastenerList.add(PART.value);
        partAndFastenerList.add(FASTENER.value);
        if (partAndFastenerList.contains(fileType)) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;

    }
}
